package cn.dubito.learning.security.core.validator.code;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * @author liliang
 * @description:
 * @date 2018/2/1.
 */
public class ValidateCode {

    /**
     * 验证码
     */
    private String code;

    /**
     * 超时时间
     */
    private LocalDateTime expireTime;


    /**
     * 延长过期时间
     *
     * @param code
     * @param expireIn
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    /**
     * 设置过期时间
     *
     * @param code
     * @param expireTime
     */
    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 判断当前时间是否在指定时间之前
     *
     * @return
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }
}